import sys
import random
import chardet
import os


current_file_path = os.path.abspath(__file__)
current_folder = os.path.dirname(current_file_path)

filterwords = []
with open(current_folder+"/conf/filter-word.txt", "rb") as f:
    result=chardet.detect(f.read())

with open(current_folder+"/conf/filter-word.txt", "r",encoding=result["encoding"]) as f:
    for line in f:
        filterwords.append(line.split("\n")[0])

definitewords = []
with open(current_folder+"/conf/area-word.txt", "r",encoding=result["encoding"]) as f:
    for line in f:
        definitewords.append(line.split("\n")[0])

dual_word_probability=1

if len(sys.argv) > 1:
    count = sys.argv[1]
    for i in range(int(count)):
        print(str(i+1)+". "+random.choice(filterwords) +
              (random.choice(filterwords)if random.randint(1,10)>dual_word_probability else "")+random.choice(definitewords) )
else:
    print(random.choice(filterwords) +
         ( random.choice(filterwords)if random.randint(1,10)>dual_word_probability else "")+random.choice(definitewords))
